
f = {}
ConfigRedisConnectors = {}
parameter_index = {}
redis_connectors = {}
mobile_service_ = nil;
creators= {}

local default_biz = "default_biz"
local preload_dir = "preload"
local biz_dir = "biz"
local local_lfs = lfs

local function master ()
    local biz_name
    local sl
    while true do
        wait_for_next_request()
        -- find slave
        biz_name = request.getSlaveID()
        sl = f[biz_name]
        if not sl then
            sl = f[default_biz]
            biz_name = default_biz
        end
        if not coroutine.resume(sl) then
            print("Coroutine die: ", biz_name)
            creators[biz_name]()
        end
    end
end

local function load_dir(dot)
    for name in local_lfs.dir(dot) do
        if string.byte(name,1) ~= 46 then
            local fqn = dot.."/"..name
            local attr = local_lfs.attributes(fqn)
            if (attr.mode == "file") then
                dofile(fqn)
            end
        end
    end
end

load_dir(preload_dir)
load_dir(biz_dir)
for l,v in pairs(creators) do
    print("Create", l)
    v()
end
master()


